<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('数据同步列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
	                            <label>同步类型： </label>
	                            <select name="tblx" id="tblx">
	                                    <option value="">全部</option>
									    <option value="dw">非税单位</option>
										<option value="xm">非税项目</option>
										<option value="yskm">预算科目</option>
										<option value="accept">划解专户数据</option>
										<option value="wlaccept">专户往来数据</option>
								</select>
							</li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:sjtb:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var syncFlag = [[${@permission.hasPermi('system:sjtb:sync')}]];
        var prefix = ctx + "system/sjtb";

        $(function() {
            var options = {
                url: prefix + "/list",
                exportUrl: prefix + "/export",
                modalName: "数据同步",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'lsh',
                    title: '流水号',
                    visible: false
                },
                {
                    field: 'tblx',
                    title: '同步类型'
                },
                {
                    field: 'tblxmc',
                    title: '同步类型名称'
                },
                {
                    title: '同步操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + syncFlag + '" href="javascript:void(0)" onclick="sync(\'' + row.lsh + '\',\''+row.tblx+'\')"><i class="fa fa-edit"></i>同步</a> ');
                        return actions.join('');
                    }
                },
                {
                    field: 'tburl',
                    title: '同步URL地址'
                },
                {
                    field: 'tbqssj',
                    title: '同步起始时间'
                },
                {
                    field: 'tbzzsj',
                    title: '同步终止时间'
                },
                {
                    field: 'tbzt',
                    title: '同步状态',
   		        	formatter: function (value, row, index) {
   		        		return statusTools(row);
   		        	}
                },
                {
                    field: 'code',
                    title: '同步状态码'
                },
                {
                    field: 'msg',
                    title: '同步返回错误消息'
                },
                {
                    field: 'errmsg',
                    title: '请求出错信息'
                },
                {
                    field: 'talcount',
                    title: '同步的总记录数'
                }]
            };
            $.table.init(options);
        });
        /* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == '1') {
    			return '发起';
    		} else if (row.status == '2') {
    			return '失败';
    		}else if (row.status == '3') {
    			return '成功';
    		}
		}
        
		function sync(lsh,tblx) { 
			if (tblx=='accept' || tblx=='wlaccept') {
	            	layer.open({
	            		type: 1,
	            		area: ['400px', '230px'],
	            		fix: false,
	            		//不固定
	            		maxmin: true,
	            		shade: 0.3,
	            		title: '同步业务数据日期选择',
	            		content: $('#syncTpl').html(),
	            		btn: ['<i class="fa fa-check"></i>同步', '<i class="fa fa-remove"></i> 取消'],
	            		// 弹层外区域关闭
	            		shadeClose: true,
	            		btn1: function(index, layero){
	            			var syncdate = layero.find('#syncdate').val();
	            			$.ajax({
	    						type : "POST",
	    						url : prefix + "/sync",
	    						data : {
	    							"lsh": lsh,
	    							"tblx": tblx,
	    							"remark": syncdate
	    						},
	    						async : false,
	    						error : function(request) {
	    							$.modal.alertError("同步操作错误");
	    						},
	    						success : function(data) {
	    							$.modal.alertWarning("同步操作成功");
	    						}
	    					});
	            		}
	            	});
				
			}
			else{
				$.modal.confirm("确认要此数据吗？", function() {
					$.ajax({
						type : "POST",
						url : prefix + "/sync",
						data : {
							"lsh": lsh,
							"tblx": tblx,
							"remark": ''
						},
						async : false,
						error : function(request) {
							$.modal.alertError("同步操作错误");
						},
						success : function(data) {
							$.modal.alertWarning("同步操作成功");
						}
					});
				});
			}
		}
    </script>
    <script id="syncTpl" type="text/template">
        <div class="form-group">
          <li>
               <label>同步时间：</label>
				<input class="form-control layer-date" id="syncdate" name="syncdate" placeholder="YYYY-MM-DD" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})">
             	<label class="laydate-icon" ></label>
          </li>
        </div>
	</script>
	
	
</body>
</html>